package(default_visibility = ["//visibility:public"])

load("@bazel_skylib//rules:common_settings.bzl", "string_flag")

string_flag(
    name = "GPU_PLATFORM",
    build_setting_default = "NVIDIA",
)

config_setting(
    name = "nvidia",
    flag_values = {
        ":GPU_PLATFORM": "NVIDIA",
    },
)

config_setting(
    name = "others",
    flag_values = {
        ":GPU_PLATFORM": "OTHERS",
    },
)

cc_binary(
    name = "libevent_hook.so",
    copts = [
        "-std=c++17",
        "-fPIC",
    ],
    linkopts = [
        "-ldl",
        "-shared",
    ] + select({
        ":nvidia": [
            "-Wl,--version-script=$(location //xpu_timer/nvidia:only_keep_nv.lds)",
            "-L/usr/local/cuda/lib64",
            "-lcudart",
        ],
        ":others": [
        ],
    }),
    linkshared = 1,
    deps = [
    ] + select({
        ":nvidia": [
            "//xpu_timer/nvidia:nvidia_hook",
            "//xpu_timer/nvidia:only_keep_nv.lds",
        ],
        ":others": [
        ],
    }),
)
